Skip to content

fix: Normalize Polygon native token addresses for Relay and balance checks#8091

Merged
OGPoyraz merged 6 commits intomainfrom
ogp/26797
Mar 3, 2026
Merged

fix: Normalize Polygon native token addresses for Relay and balance checks#8091
OGPoyraz merged 6 commits intomainfrom
ogp/26797

Conversation

@OGPoyraz
Copy link
Member

@OGPoyraz OGPoyraz commented Mar 3, 2026

Explanation

This PR fixes Polygon native token address normalization across Relay quote/submit flows and MetaMask balance checks.

References

Fix in action:

Predict deposit

Pol_deposit.mov

Predict withdraw

Pol_withdraw.mov

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Medium risk because it changes how token addresses are transformed in Relay quote/submit flows and balance validation, which can impact transaction execution on Polygon; scope is limited and covered by added unit tests.

Overview
Fixes Polygon native token handling by introducing normalizeTokenAddress (with TokenAddressTarget) to consistently map between MetaMask’s Polygon native address (0x…1010) and Relay’s native/zero-address format.

Relay quote requests now normalize both source and destination token addresses before calling Relay, and Relay submit’s live balance validation normalizes the source token address before calling getLiveTokenBalance. Tests were updated/added to cover Polygon source/target normalization and the new utility, and the changelog documents the fix.

Written by Cursor Bugbot for commit 3e0e5cc. This will update automatically on new commits. Configure here.

@OGPoyraz OGPoyraz marked this pull request as ready for review March 3, 2026 09:26
@OGPoyraz OGPoyraz requested review from a team as code owners March 3, 2026 09:26
return tokenAddress;
}

const polygonNativeTokenAddress = getNativeToken(CHAIN_ID_POLYGON);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, could use chainId here as already verified above, and may impact other chains in future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, done

});
}

type NormalizeTokenAddressOptions = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the type is very explicit, extensible and readable, could we just expose normalizeTokenAddress and remove the small wrappers?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

});
}

type NormalizeTokenAddressOptions = {
Copy link
Member

@matthewwalsh0 matthewwalsh0 Mar 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe an enum if we expose the below since we don't use the value as a string but just for branching?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

): Promise<void> {
const { from, sourceChainId, sourceTokenAddress } = quote.request;

const normalizedSourceTokenAddress = normalizeTokenAddressForMM(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we safe to just do this here? Is there value in mutating the quote as soon as we get it in relay-quotes.ts so we normalize both sides in the same place?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this will be fine and still necessary. Because getLiveTokenBalance below is especially comparing the native token balance via getNativeToken utility here:
https://github.com/MetaMask/core/blob/main/packages/transaction-pay-controller/src/utils/token.ts#L312

Just to be clear, my aim was not mutating quotes so quotes are same, but the quote requests + especially this validation.

@OGPoyraz OGPoyraz requested a review from matthewwalsh0 March 3, 2026 12:12
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

@OGPoyraz OGPoyraz added this pull request to the merge queue Mar 3, 2026
Merged via the queue into main with commit 00044a7 Mar 3, 2026
318 checks passed
@OGPoyraz OGPoyraz deleted the ogp/26797 branch March 3, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Predict deposits with POL on Polygon failing

2 participants